package edu.ncsu.csc.csc454.project;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

import edu.ncsu.csc.csc454.project.gui.ApplicationWheelGUI;
import edu.ncsu.csc.csc454.project.gui.wheel_panel.WheelDisplay;
import edu.ncsu.csc.csc454.project.wheel.NodeChain;
import edu.ncsu.csc.csc454.project.wheel.WheelConfig;

/**
 * Represents the application's back end by processing any event-driven requests made by the user
 * through the GUI or the underlying WheelDisplay class. The MVC "Controller" class, this guy calls
 * all of the shots.
 * @author Team AW
 * @version 0.1
 */
public class ApplicationWheel {

    private static NodeChain    chain;

    private ApplicationWheelGUI gui;

    private WheelDisplay        wheel;

    /**
     * Constructs a new controller.
     */
    public ApplicationWheel() {
        WheelConfig wc = new WheelConfig();
        chain = wc.getChain();

        gui = new ApplicationWheelGUI();
        wheel = gui.getWheel();

        armButtons();
        gui.display();
    }

    private void armButtons() {
        gui.getMenuButton().addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                wheel.showAboutDialog();
            }
        });
    }

    public static NodeChain getChain() {
        return chain;
    }

    /**
     * Application entry point.
     * @param args not currently used.
     */
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null,
                            "Error setting Look and Feel. Using default.\n\nDetails:\n"
                                    + e.toString() + "\n\nMessage:\n" + e.getMessage(),
                            "Fatal UIManager failure", JOptionPane.ERROR_MESSAGE);
                }
                new ApplicationWheel();
            }
        });
    }
}
